from time import sleep

from selenium import webdriver


def open_browser(browser):
    try:
        data = getattr(webdriver, browser)()
    except Exception as e:
        print(e)
        data = webdriver.Chrome()
    return data


class Key:
    def __init__(self, browser):
        # driver = webdriver.Chrome()
        self.driver = open_browser(browser)

    def open(self, url):
        self.driver.get(url)

    def locate(self, name, value):
        return self.driver.find_element(name, value)

    def input(self, name, value, inputdata):
        self.locate(name, value).send_keys(inputdata)

    def click(self, name, value):
        self.locate(name, value).click()

    def sleep(self, time):
        sleep(int(time))

    def quit(self):
        self.driver.quit()
